package IO;
/*文件的复制原理：
  从一个输入流中读取数据，然后通过输出流写入目标文件
  一边读一边写

 */

import java.io.*;

public class CopyFile {
    public static void main(String[] args) {
  copy("C:\\Users\\Administrator\\Desktop\\File\\van.txt","C:\\Users\\Administrator\\Desktop\\新建文件夹 (2)\\van.txt");

    }
    private static void copy(String src,String target){
        File srcFile = new File(src);
        File targetFile = new File(target);
        Reader in = null;
        Writer out = null;
        try {
             in = new FileReader(srcFile);
             out = new FileWriter(targetFile);
            char[] chars = new char[1];
            int len = -1;
            while((len =in.read(chars))!=-1){
                out.write(chars);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
                try {
                    if(in!=null) in.close();
                    if(out!=null) out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
        }

    }

}
